#include <iostream>
#include <math.h>

using namespace std;
typedef unsigned long long BIG;

int main()
{
    BIG x = 600851475143ull;
    BIG i = 3, j, n = 2, d, max, result = 0;
    BIG * p = new BIG[x/3];
    p[0] = 2; p[1] = 3;

    top:
    while(x>1)
    {
        for(BIG a=0; a<n; a++)
        {
            if(x%p[a]==0)
            {
                x/=p[a];
                result = x;
                goto top;
            }
        }

        max = BIG(sqrt(x));
        while(i < max)
        {
            d = BIG(sqrt(i+=2));
            j = 1;
            while(d >= p[j] && i%p[j]) j++;
            if(d < p[j])
            {
                p[n++] = i;
                if(x%i == 0)
                {
                    result = x;
                    x/=i;
                    goto top;
                }
            }
        }
        result = x;
        break;
    }

    cout << result << endl;
    return 0;
};
